/*
 * @Description:
 * @Author: Zzt
 * @Date: 2023-01-07 09:57:21
 * @LastEditTime: 2023-02-10 20:04:56
 */
import MouldType from './MouldType';

import styles from '../styles/index.module.scss';
import classNames from 'classnames/bind';
import { useDetectionTemplateContext } from '../contexts/DetectionTemplateContext';
import PageList from './PageList';
import PageOperate from './PageOperate';
import { useEffect, useState } from 'react';
import { fetchATListByFondId } from '@/api/archivesType';
import { IArchiveType } from '@/interfaces/archiveType';

const cx = classNames.bind(styles);
const PageContent = () => {
  const { setTemplateType, selectFond } = useDetectionTemplateContext();
  const [archiveTypeList, setArchiveTypeList] = useState([]);

  const typeChange = (detectionType: any) => {
    setTemplateType(detectionType);
    console.log('{ tplType, methodType }', detectionType);
  };
  // 切换全宗自动加载档案类型
  useEffect(() => {
    if (selectFond.id) {
      fetchATListByFondId(selectFond.id, 1).then((res) => {
        const _atList: IArchiveType[] = res.data;
        setArchiveTypeList(_atList);
      });
    }
  }, [selectFond]);

  return (
    <>
      <div className={cx('out-flex')}>
        <MouldType onChange={typeChange} />
        <div className={cx('all-width')}>
          <PageOperate archiveTypeList={archiveTypeList} />
          <PageList archiveTypeList={archiveTypeList} />
        </div>
      </div>
    </>
  );
};
export default PageContent;
